home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / -serious- / programming / other / dopus412-gpl / library / functions.a < prev    next >
Text File  |  2000-02-28  |  9KB  |  553 lines

  1. ; Directory Opus 4
  2. ; Original GPL release version 4.12
  3. ; Copyright 1993-2000 Jonathan Potter
  4. ; This program is free software; you can redistribute it and/or
  5. ; modify it under the terms of the GNU General Public License
  6. ; as published by the Free Software Foundation; either version 2
  7. ; of the License, or (at your option) any later version.
  8. ; This program is distributed in the hope that it will be useful,
  9. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11. ; GNU General Public License for more details.
  12. ; You should have received a copy of the GNU General Public License
  13. ; along with this program; if not, write to the Free Software
  14. ; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  15. ; All users of Directory Opus 4 (including versions distributed
  16. ; under the GPL) are entitled to upgrade to the latest version of
  17. ; Directory Opus version 5 at a reduced price. Please see
  18. ; http://www.gpsoft.com.au for more information.
  19. ; The release of Directory Opus 4 under the GPL in NO WAY affects
  20. ; the existing commercial status of Directory Opus 5.
  21.  
  22.  
  23.     SECTION    code
  24.  
  25.     INCLUDE "exec/types.i"
  26.     INCLUDE "exec/initializers.i"
  27.     INCLUDE "exec/libraries.i"
  28.     INCLUDE "exec/lists.i"
  29.     INCLUDE "exec/alerts.i"
  30.     INCLUDE "exec/resident.i"
  31.     INCLUDE "exec/ports.i"
  32.     INCLUDE "exec/io.i"
  33.     INCLUDE "libraries/dos.i"
  34.     INCLUDE "graphics/rastport.i"
  35.  
  36.     INCLUDE "asmsupp.i"
  37.     INCLUDE "dopusbase.i"
  38.  
  39.     XREF _IntuitionBase
  40.     XREF _GfxBase
  41.  
  42.     XDEF endcode
  43.     XDEF GetWBScreen
  44.     XDEF Seed
  45.     XDEF Random
  46.     XDEF StrToUpper
  47.     XDEF StrToLower
  48.     XDEF DisableGadget
  49.     XDEF EnableGadget
  50.     XDEF GhostGadget
  51.     XDEF _SwapMem
  52.     XDEF _LSprintf
  53.     XDEF LSprintf
  54.     XDEF LCreateExtIO
  55.     XDEF LCreatePort
  56.     XDEF LDeleteExtIO
  57.     XDEF LDeletePort
  58.     XDEF LToUpper
  59.     XDEF LToLower
  60.     XDEF LStrCat
  61.     XDEF LStrnCat
  62.     XDEF LStrCpy
  63.     XDEF LStrnCpy
  64.     XDEF LStrCmpI
  65.     XDEF LStrnCmpI
  66.     XDEF LStrCmp
  67.     XDEF LStrnCmp
  68.  
  69.     
  70. wbname
  71.     dc.b 'Workbench',0
  72. rand
  73.     ds.l 2
  74. ditherdata
  75.     dc.w $8888,$2222
  76.  
  77. GetWBScreen:
  78.     movem.l a2/a3/a5/a6,-(sp)
  79.     move.l _IntuitionBase,a6
  80.     move.w 20(a6),d0
  81.     cmp.w #36,d0
  82.     blt getwb13
  83.     move.l a0,a2
  84.     lea wbname(pc),a0
  85.     jsr _LVOLockPubScreen(a6)
  86.     move.l d0,a3
  87.     move.l d0,a0
  88.     move.l a2,a1
  89.     move.l #346,d0
  90.     move.l 4,a6
  91.     jsr _LVOCopyMem(a6)
  92.     move.l a5,a6
  93.     move.l #0,a0
  94.     move.l a3,a1
  95.     move.l _IntuitionBase,a6
  96.     jsr _LVOUnlockPubScreen(a6)
  97.     bra endgetscr
  98. getwb13:
  99.     move.l #346,d0
  100.     moveq.l #1,d1
  101.     move.l #0,a1
  102.     jsr _LVOGetScreenData(a6)
  103. endgetscr:
  104.     movem.l (sp)+,a2/a3/a5/a6
  105.     rts
  106.  
  107. Seed:
  108.     move.l d0,d1
  109.     not.l d1
  110.     movem.l d0/d1,rand
  111. longrnd:
  112.   movem.l d2-d3,-(sp) 
  113.     movem.l rand,d0/d1
  114.     andi.b #$0e,d0
  115.     ori.b #$20,d0
  116.     move.l d0,d2
  117.     move.l d1,d3
  118.     add.l d2,d2 
  119.     addx.l d3,d3
  120.     add.l d2,d0
  121.     addx.l d3,d1
  122.     swap d3
  123.     swap d2
  124.     move.w d2,d3
  125.     clr.w d2
  126.     add.l d2,d0
  127.     addx.l d3,d1
  128.     movem.l d0/d1,rand
  129.     move.l d1,d0
  130.     movem.l (sp)+,d2-d3
  131.     rts
  132.  
  133. Random:
  134.     move.w d2,-(sp)
  135.     move.w d0,d2
  136.     beq.s skip
  137.     bsr.s longrnd
  138.     clr.w d0
  139.     swap d0
  140.     divu.w d2,d0
  141.     clr.w d0
  142.     swap d0
  143. skip:
  144.     move.w (sp)+,d2
  145.     rts
  146.  
  147. StrToUpper:
  148.     move.b (a0)+,d0
  149.     bsr LToUpper
  150.     move.b d0,(a1)+
  151.     bne.s StrToUpper
  152.     rts
  153.  
  154. StrToLower:
  155.     move.b (a0)+,d0
  156.     bsr LToLower
  157.     move.b d0,(a1)+
  158.     bne.s StrToLower
  159.     rts
  160.  
  161. DisableGadget:
  162.     btst.b #0,12(a0)
  163.     bne disabled
  164.     bset.b #0,12(a0)
  165.     bsr GhostGadget
  166. disabled:
  167.     rts
  168.  
  169. EnableGadget:
  170.     btst.b #0,12(a0)
  171.     beq enabled
  172.     bclr.b #0,12(a0)
  173.     bsr GhostGadget
  174. enabled:
  175.     rts
  176.  
  177. GhostGadget:
  178.     movem.l a2/a3/a6/d2-d5,-(sp)
  179.     move.b 28(a1),-(sp)
  180.     move.l a0,a2
  181.     move.l a1,a3
  182.     move.l d0,d4
  183.     move.l d1,d5
  184.  
  185.     moveq.l #2,d0    
  186.     move.l db_GfxBase(a6),a6
  187.     jsr _LVOSetDrMd(a6)
  188.  
  189.     move.l a3,a1    
  190.     lea ditherdata(pc),a0
  191.     move.l a0,8(a1)
  192.     move.b #1,29(a1)
  193.  
  194.     move.l d4,d0
  195.     add.w 4(a2),d0
  196.     move.l d5,d1
  197.     add.w 6(a2),d1
  198.     moveq.l #0,d2
  199.     move.w 4(a2),d2
  200.     add.w 8(a2),d2
  201.     subq.l #1,d2
  202.     sub.l d4,d2
  203.     moveq.l #0,d3
  204.     move.w 6(a2),d3
  205.     add.w 10(a2),d3
  206.     subq.l #1,d3
  207.     sub.l d5,d3
  208.     jsr _LVORectFill(a6)
  209.  
  210.     move.l a3,a1    
  211.     move.l #0,8(a1)
  212.     move.b #0,29(a1)
  213.  
  214.     moveq.l #0,d0
  215.     move.b (sp)+,d0
  216.     jsr _LVOSetDrMd(a6)
  217.     movem.l (sp)+,a2/a3/a6/d2-d5
  218.     rts
  219.  
  220. DrawRadioButton:
  221.     movem.l a2-a4/a6/d2-d7,-(sp)
  222.  
  223.     move.l db_GfxBase(a6),a6
  224.     move.l a0,a2
  225.     move.l d0,d6
  226.     move.l d1,d7
  227.  
  228.     move.l a2,a1
  229.     move.l d4,d0
  230.     jsr _LVOSetAPen(a6)
  231.  
  232.     move.l a2,a1
  233.     move.l d6,d0
  234.     move.l d0,a3
  235.     move.l d7,d1
  236.     subq.l #1,d1
  237.     move.l d1,a4
  238.     jsr _LVOMove(a6)
  239.  
  240.     move.l a2,a1
  241.     move.l d6,d0
  242.     add.l d2,d0
  243.     addq.l #1,d0
  244.     move.l a4,d1
  245.     subq.l #2,d1
  246.     jsr _LVODraw(a6)
  247.  
  248.     move.l a2,a1
  249.     move.l a3,d0
  250.     move.l a4,d1
  251.     jsr _LVOMove(a6)
  252.  
  253.     move.l a2,a1
  254.     move.l a3,d0
  255.     move.l d7,d1
  256.     add.l d3,d1
  257.     jsr _LVODraw(a6)
  258.  
  259.     move.l a2,a1
  260.     move.l d6,d0
  261.     subq.l #1,d0
  262.     move.l d0,a3
  263.     move.l a4,d1
  264.     jsr _LVOMove(a6)
  265.  
  266.     move.l a2,a1
  267.     move.l a3,d0
  268.     move.l d7,d1
  269.     add.l d3,d1
  270.     move.l d1,a4
  271.     subq.l #1,d1
  272.     jsr _LVODraw(a6)
  273.  
  274.     move.l a2,a1
  275.     move.l d5,d0
  276.     jsr _LVOSetAPen(a6)
  277.  
  278.     move.l a2,a1
  279.     move.l a3,d0
  280.     move.l a4,d1
  281.     jsr _LVOMove(a6)
  282.  
  283.     move.l a2,a1    
  284.     move.l d6,d0
  285.     add.l d2,d0
  286.     move.l d0,a3
  287.     addq.l #1,d0
  288.     move.l a4,d1
  289.     jsr _LVODraw(a6)
  290.  
  291.     move.l a2,a1
  292.     move.l a3,d0
  293.     addq.l #1,d0
  294.     move.l d7,d1
  295.     subq.l #1,d1
  296.     jsr _LVODraw(a6)
  297.  
  298.     move.l a2,a1
  299.     move.l a3,d0
  300.     move.l a4,d1
  301.     jsr _LVOMove(a6)
  302.  
  303.     move.l a2,a1
  304.     move.l a3,d0
  305.     move.l d7,d1
  306.     jsr _LVODraw(a6)
  307.  
  308.     movem.l (sp)+,a2-a4/a6/d2-d7
  309.     rts
  310.  
  311. _SwapMem:
  312.     move.b (a0),d1
  313.     move.b (a1),(a0)+
  314.     move.b d1,(a1)+
  315.     subq.l #1,d0
  316.     bne.s _SwapMem
  317.     rts
  318.  
  319. _LSprintf:
  320. LSprintf:
  321.     movem.l a2/a3/a6,-(sp)
  322.     move.l 4*4(sp),a3
  323.     move.l 5*4(sp),a0
  324.     lea.l 6*4(sp),a1
  325.     lea.l stuffChar(pc),a2
  326.     move.l 4,a6
  327.     jsr _LVORawDoFmt(a6)
  328.     movem.l (sp)+,a2/a3/a6
  329.     rts
  330.  
  331. stuffChar:
  332.     move.b d0,(a3)+
  333.     rts
  334.  
  335. LCreateExtIO:
  336.     movem.l a6/d2/d3,-(sp)
  337.     move.l a0,d2
  338.     moveq.l #0,d3
  339.     move.w d0,d3
  340.     beq.s endextio
  341.     move.l #196608,d1
  342.     move.l 4,a6
  343.     jsr _LVOAllocMem(a6)
  344.     tst.l d0
  345.     beq.s endextio
  346.     move.l d0,a0
  347.     move.b #NT_MESSAGE,LN_TYPE(a0)
  348.     move.w d3,MN_LENGTH(a0)
  349.     move.l d2,MN_REPLYPORT(a0)
  350.     move.l a0,d0
  351.     movem.l (sp)+,a6/d2/d3
  352.     rts
  353. endextio:
  354.     movem.l (sp)+,a6/d2/d3
  355.     moveq.l #0,d0
  356.     rts
  357.  
  358. LCreatePort:
  359.     movem.l a2/a3/a6/d2/d3,-(sp)
  360.     move.l a0,a2
  361.     move.l d0,d2
  362.     move.l #-1,d0
  363.     move.l 4,a6
  364.     jsr _LVOAllocSignal(a6)
  365.     cmp.b #-1,d0
  366.     beq endport
  367.     move.b d0,d3
  368.     move.l #MP_SIZE,d0
  369.     move.l #196608,d1
  370.     move.l 4,a6
  371.     jsr _LVOAllocMem(a6)
  372.     tst.l d0
  373.     beq.s endport1
  374.     move.l d0,a3
  375.     move.l a2,LN_NAME(a3)
  376.     move.b d2,LN_PRI(a3)
  377.     move.b #NT_MSGPORT,LN_TYPE(a3)
  378.     move.b #PA_SIGNAL,MP_FLAGS(a3)
  379.     move.b d3,MP_SIGBIT(a3)
  380.     move.l #0,a1
  381.     move.l 4,a6
  382.     jsr _LVOFindTask(a6)
  383.     move.l d0,MP_SIGTASK(a3)
  384.     cmp.l #0,a2
  385.     beq.s noname
  386.     move.l a3,a1
  387.     move.l 4,a6
  388.     jsr _LVOAddPort(a6)
  389.     bra.s endgotport
  390. noname:
  391.     lea MP_MSGLIST(a3),a0
  392.     move.l a0,LH_HEAD(a0)
  393.     addq.l #4,LH_HEAD(a0)
  394.     clr.l LH_TAIL(a0)
  395.     move.l a0,LH_TAILPRED(a0)
  396. endgotport:
  397.     move.l a3,d0
  398.     movem.l (sp)+,a2/a3/a6/d2/d3
  399.     rts
  400. endport1:
  401.     move.l 4,a6
  402.     jsr _LVOFreeSignal(a6)
  403. endport:
  404.     movem.l (sp)+,a2/a3/a6/d2/d3
  405.     rts
  406.  
  407. LDeleteExtIO:
  408.     move.l a6,-(sp)
  409.     move.b #-1,LN_TYPE(a0)
  410.     move.l #-1,MN_REPLYPORT(a0)
  411.     move.l #-1,IO_DEVICE(a0)
  412.     move.l a0,a1
  413.     moveq.l #0,d0
  414.     move.w MN_LENGTH(a0),d0
  415.     move.l 4,a6
  416.     jsr _LVOFreeMem(a6)
  417.     move.l (sp)+,a6
  418.     rts
  419.  
  420. LDeletePort:
  421.     movem.l a2/a6,-(sp)
  422.     move.l a0,a2
  423.     move.l LN_NAME(a2),d0
  424.     tst.l d0
  425.     beq.s nonamefree
  426.     move.l a0,a1
  427.     move.l 4,a6
  428.     jsr _LVORemPort(a6)
  429. nonamefree:
  430.     move.l #-1,MP_SIGTASK(a2)
  431.     lea MP_MSGLIST(a2),a0
  432.     move.l #-1,LH_HEAD(a0)
  433.     moveq.l #0,d0
  434.     move.b MP_SIGBIT(a2),d0
  435.     move.l 4,a6
  436.     jsr _LVOFreeSignal(a6)
  437.     move.l a2,a1
  438.     move.l #MP_SIZE,d0
  439.     move.l 4,a6
  440.     jsr _LVOFreeMem(a6)
  441.     movem.l (sp)+,a2/a6
  442.     rts
  443.  
  444. LToUpper:
  445.     cmp.b #'a'-1,d0
  446.     bls tu_done
  447.     cmp.b #'z',d0
  448.     bhi tu_done
  449.     sub.b #'a'-'A',d0
  450. tu_done:
  451.     rts
  452.  
  453. LToLower:
  454.     cmp.b #'A'-1,d0
  455.     bls tl_done
  456.     cmp.b #'Z',d0
  457.     bhi tl_done
  458.     add.b #'a'-'A',d0
  459. tl_done:
  460.     rts
  461.  
  462. LStrCat:
  463.     move.l #$ffff,d0
  464. LStrnCat:
  465.     tst.b (a0)+
  466.     bne.s    LStrnCat
  467.     sub.l #1,a0
  468.     subq.l #1,d0
  469. catloop:
  470.     move.b (a1)+,(a0)+
  471.     dbeq d0,catloop
  472.     beq.s endcat
  473.     clr.b (a0)
  474. endcat:
  475.     rts
  476.  
  477. LStrCpy:
  478.     move.b (a1)+,(a0)+
  479.     bne.s    LStrCpy
  480.     rts
  481.  
  482. LStrnCpy:
  483.     move.b (a1)+,(a0)+
  484.     beq.s endstrncpy
  485.     dbeq d0,LStrnCpy
  486.     move.b #0,-(a0)
  487. endstrncpy:
  488.     rts
  489.  
  490. LStrCmpI:
  491.     move.l #$7fff,d0
  492. LStrnCmpI:
  493.     move.l d2,-(sp)
  494.     move.l d0,d2
  495.     subq.l #1,d2
  496.     bmi equal
  497. cmploop:
  498.     move.b (a0)+,d0
  499.     ext.l d0
  500.     bsr LToUpper
  501.     move.b d0,d1
  502.     move.b (a1)+,d0
  503.     ext.l d0
  504.     bsr LToUpper
  505.     cmp.b d0,d1
  506.     blt less
  507.     bgt greater
  508.     tst.b d1
  509.     dbeq d2,cmploop
  510. equal:
  511.     moveq.l #0,d0
  512.     move.l (sp)+,d2
  513.     rts
  514. greater:
  515.     moveq.l #1,d0
  516.     move.l (sp)+,d2
  517.     rts
  518. less:
  519.     move.l #-1,d0
  520.     move.l (sp)+,d2
  521.     rts
  522.  
  523. LStrCmp:
  524.     move.l #$7fff,d0
  525. LStrnCmp:
  526.     subq.l #1,d0
  527.     bmi equal1
  528.     moveq.l #0,d1
  529. cmploop1:
  530.     move.b (a0)+,d1
  531.     cmp.b (a1)+,d1
  532.     blt less1
  533.     bgt greater1
  534.     tst.b d1
  535.     dbeq d0,cmploop1
  536. equal1:
  537.     moveq.l #0,d0
  538.     rts
  539. greater1:
  540.     moveq.l #1,d0
  541.     rts
  542. less1:
  543.     move.l #-1,d0
  544.     rts
  545.  
  546. endcode:
  547.     END
  548.